﻿using Ingenta.IRepository;
using Ingenta.Model;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Threading.Tasks;

namespace Ingenta.Repository
{
    /// <summary>
    /// Describe：仓储实现类
    /// </summary>
    /// <typeparam name="TEntity">实体模型</typeparam>
    public class BaseRepository<TEntity> : IBaseRepository<TEntity> where TEntity : class
    {
        EFDBContent db = new EFDBContent();

        DbSet<TEntity> _dbSet;

        public BaseRepository()
        {
            _dbSet = db.Set<TEntity>();
        }

        #region 查询
        /// <summary>
        /// 单表查询
        /// </summary>
        /// <param name="predicate"></param>
        /// <returns></returns>
        public List<TEntity> QueryWhere(Expression<Func<TEntity, bool>> predicate)
        {
            return _dbSet.Where(predicate).ToList();
        }
        #endregion

        public void Add(TEntity model)
        {
            _dbSet.Add(model);
        }

        public int SaveChanges()
        {
            return db.SaveChanges();
        }
    }
}